<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>登录</title>
	<meta name="keywords" content="">
    <meta name="description" content="">
    <link href="${pageContext.request.contextPath}/static/front/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/front/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/front/css/animate.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/front/css/style.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/front/css/login.css" rel="stylesheet">
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
    <script>
        if (window.top !== window.self) {
            window.top.location = window.location;
        }
    </script>

</head>

<body class="signin">
    <div class="signinpanel">
        <div class="row">
            <div class="col-sm-12">
                <form id="ajax_form" method="post" onsubmit="return false" style="width:400px">
                    <h4 class="no-margins">登录：</h4>
                    <p class="m-t-md">登录到H+后台主题UI框架</p>
                    <input type="text" id="name" name="name" class="form-control uname" placeholder="用户名" />
                    <input type="password" id="password" name="password" class="form-control pword m-b" placeholder="密码" />
                    <input type="text" id="checkCode" name="checkCode" placeholder="验证码"/>
                    <img id="codeImgId" src="<%=request.getContextPath()%>/checkImg" onclick="refreshCode()"><br/>
                    <a href="">忘记密码了？</a><br/>
                    <button class="btn btn-success btn-block" onclick="submitForm()">登录</button>
                </form>
            </div>
        </div>
        <div class="signup-footer">
            <div class="pull-left">
                &copy; GSKAdmin
            </div>
        </div>
    </div>
    
    <script src="${pageContext.request.contextPath}/static/front/js/jquery-1.11.3.js" type="text/javascript" charset="utf-8"></script>
	<script src="${pageContext.request.contextPath}/static/front/js/layer/layer/layer.js" type="text/javascript" charset="utf-8"></script>
	<script src="${pageContext.request.contextPath}/static/front/js/layer/layer/mylayer.js" type="text/javascript" charset="utf-8"></script>
	<script src="${pageContext.request.contextPath}/static/front/js/layer/layer/util.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
    	function submitForm(){
    		console.log("submitForm");
    		var name = $("#name").val();
    		var password = $("#password").val();
    		
    		if(util.isEmpty(name)){
    			mylayer.errorMsg("用户名不能为空");
    			return;
    		}
    		
    		var pattern = /^\w{4,8}$/;
    		if(!pattern.test(name)){
    			mylayer.errorMsg("用户名非法，请输入4-8位数字或字母");
    			return;
    		}
    		
    		if(util.isEmpty(password)){
    			mylayer.errorMsg("密码不能为空");
    			return;
    		}
    		
    		var pattern = /^\w{3}$/;
    		if(!pattern.test(password)){
    			mylayer.errorMsg("密码格式非法，请输入3位数字或字母");
    			return;
    		}
    		$.ajax({
    			url : "${pageContext.request.contextPath}/user/login.action",
    			type : "post",
    			dataType : "json",
    			data : $("#ajax_form").serialize(),
    			success : function(jsonObj){
    				console.log(jsonObj);
    				if(jsonObj.code == 0){
    					mylayer.successMsgUrl(jsonObj.msg,"${pageContext.request.contextPath}/product/getProductListPage.action");
    				}else{
    					mylayer.errorMsg(jsonObj.msg);
    				}
    			}
    		});
    	}
    	function refreshCode(){
    		$("#codeImgId").attr("src","${pageContext.request.contextPath}/checkImg?" + Math.random());
		}
	</script>	
</head>
<body>
	
</body>
</html>